﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UFSoft.UBF.Util.Log;
using UFIDA.U9.BS.Job.RequestClient;
using UFSoft.UBF.UI.ControlModel;
using UFSoft.UBF.UI.Engine.Builder;
using UFSoft.UBF.UI.WebControlAdapter;
using UFSoft.UBF.UI.IView;
using System.Data;
using static UFIDA.U9C.Cust.ZL.PlugUI.TemplateClass;

namespace UFIDA.U9C.Cust.ZL.PlugUI
{
    /// <summary>
    /// 销售订单变更单界面
    /// </summary>
    public class SOMainUIFormWebPart : UFSoft.UBF.UI.Custom.ExtendedPartBase
    {
        private UFIDA.U9.SCM.SM.SOUIModel.StandardSOMainUIFormWebPart _strongPart;
        private static ILogger logger = LoggerManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public override void AfterInit(IPart Part, EventArgs args)
        {
            _strongPart = Part as UFIDA.U9.SCM.SM.SOUIModel.StandardSOMainUIFormWebPart;
            base.AfterInit(Part, args);
            //添加红冲按钮
            //2.Card里面增加按钮
            //设置按钮在容器中的位置
            #region 2.Card里面增加按钮
            IUFCard card = (IUFCard)_strongPart.GetUFControlByName(_strongPart.TopLevelContainer, "Card0");//一般情况下名称为Card0,具体请使用F12查看
            IUFButton btnRedAR = new UFWebButtonAdapter();
            btnRedAR.Text = "红冲应收";
            btnRedAR.ID = "btnRedAR";
            btnRedAR.AutoPostBack = true;
            card.Controls.Add(btnRedAR);
            btnRedAR.Click += new EventHandler(btnRedAR_Click);
            CommonFunction.Layout(card, btnRedAR, 18, 0);   //一般为从左往右按钮个数乘以2
            #endregion

        }

        void btnRedAR_Click(object sender, EventArgs e)
        {
            try
            {


                if (this._strongPart.Model.SO.FocusedRecord.ID > 0)
                {
                    UFIDA.U9C.Cust.ZLZ.RedARBP.Proxy.OperationProxy bp = new ZLZ.RedARBP.Proxy.OperationProxy() ;
                    bp.SOID = this._strongPart.Model.SO.FocusedRecord.ID.ToString();
                    UFIDA.U9C.Cust.ZLZ.RedARBP.ReturnDtoData res = bp.Do();
                    this._strongPart.ShowWindowStatus("红冲返回：" + res.Message, true);
                }
                else
                {
                    this._strongPart.Model.ErrorMessage.Message = "无可红冲单据";
                }
            }
            catch (Exception ex)
            {
                this._strongPart.Model.ErrorMessage.Message = "红冲失败，" + ex.Message;
            }

        }



    }
}

